//
//  HotTribeCell.m
//  yigou
//
//  Created by SunChao on 17/3/6.
//  Copyright © 2017年 hanyiwang. All rights reserved.
//

#import "HotTribeCell.h"
#import "CustomImgView.h"


#define imgWidth 90
#define imgHeight 90
#define imgSpace 7
@implementation HotTribeCell


- (void)awakeFromNib {
    [super awakeFromNib];
    self.titleLabel.frame = CGRectMake(15, 15, 100, 20);
    self.titleLabel.font = [UIFont systemFontOfSize:15];
    self.titleLabel.text = @"热门部落";
   
   
}
- (void)fillDataWithArray:(NSMutableArray *)tribeArray{
    self.tribeArr = [NSMutableArray arrayWithArray:tribeArray];
    if (self.scrollView == nil) {
        self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(15, 40, SCREEN_WIDTH-30, 140)];
        self.scrollView.showsHorizontalScrollIndicator = NO;
        [self addSubview:self.scrollView];
    }
    NSUInteger numOfBlocks = tribeArray.count;
    self.scrollView.contentSize = CGSizeMake(imgWidth * numOfBlocks+imgSpace*(numOfBlocks-1), 0);
    for(NSUInteger i = 0;  i< numOfBlocks; i++) {
        NSDictionary *dic = [tribeArray objectAtIndex:i];
        CustomImgView *block = [CustomImgView new];
        [block.img sd_setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"tribe_logo"]] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
        block.title.text = [dic objectForKey:@"tribe_name"];
        block.title.font = [UIFont systemFontOfSize:13];
        block.frame = CGRectMake((imgWidth+imgSpace)*i, 10, imgWidth, 125);
        block.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapImgAction:)];
        block.tag = i+100;
        [block addGestureRecognizer:tap];
        [self.scrollView addSubview:block];
        
    }

}

- (void)tapImgAction:(UITapGestureRecognizer *)tap{
    
    NSDictionary *dic = [self.tribeArr objectAtIndex:tap.view.tag - 100];
    
    NSString *tribeID = [dic objectForKey:@"tribe_id"];
    if ([_delegate respondsToSelector:@selector(didClickHotTribeWithTribeID:)]) {
        
        [_delegate didClickHotTribeWithTribeID:tribeID];
    }
}


@end
